package com.meessiom.train.crm.employee.controller;
import com.meessiom.train.crm.employee.model.Employee;
import com.meessiom.train.crm.employee.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@CrossOrigin("*") //是用来处理跨源资源共享
@RestController //控制器
@RequestMapping("/api/v1/employees") //这是控制器的地址
@Slf4j//日志
public class EmployeeController {

    @Autowired  //成员变量、方法和构造函数进行标注，来完成自动装配的工作
    private EmployeeService employeeService;
    @GetMapping//用于处理请求方法
    public List<Employee> getAllEmployees() {
        log.info("获得了来自客户端的获得学生列表的的请求");
        return employeeService.getAllEmployees();
    }

    @GetMapping({"{id}"})
    public ResponseEntity<Employee> getEmployeeById(@PathVariable long id) {
        Employee employee = this.employeeService.getEmployeeById(id);
        return ResponseEntity.ok(employee);
    }




    @DeleteMapping({"{id}"})
    public ResponseEntity<HttpStatus> deleteEmployee(@PathVariable long id) {
        this.employeeService.deleteEmployee(id);
        return new ResponseEntity(HttpStatus.NO_CONTENT);


    }

}
